Hello I have a test 开发者_Python百科table with name mytable and with following data
id name surname
==================
1 sotos val
2 john rik
3 peter ask
How can id export for example the second row in mysql using php knowing the id?
Use:
SELECT t.id,
t.name,
t.surname
FROM MYTABLE t
WHERE t.id = mysql_real_escape_string($id)
Reference:
- mysql_real_escape_string()
- mysql_query
PHP
<?php
$query = "SELECT t.id,
t.name,
t.surname
FROM MYTABLE t
WHERE t.id = mysql_real_escape_string($id)";
$result = mysql_query($query);
while ($row = mysql_fetch_assoc($result)) {
echo $row['id'];
echo $row['name'];
echo $row['surname'];
}
?>
If by export you mean dump data into ready-to-use SQL query try this one:
$sql_query = shell_exec('x:\path\to\mysqldump.exe -t --compact -u DB_USERNAME --password=DB_PASSWORD DB_NAME mytable --where="id = 2"');
Will produce something like:
INSERT INTO `mytable` VALUES(2,'john','rik');
精彩评论