how i could retrieve data from mysql using php code
I'm still a beginner in the PHP so I need your help ... I have a small database Containing
- id & content & links
I want to retrieve the content data using 开发者_StackOverflow中文版the id . so I need the php code which could help me
<?php
mysql_connect("localhost", "dbuser", "dbpass");
mysql_select_db("dbname");
$id = 5;
$q = mysql_query("SELECT * FROM table_name WHERE id = {$id}");
$r = mysql_fetch_object($q);
echo $r->links;
?>
Supposing you need to get only one row from table.
if your database is mySQL
read http://www.w3schools.com/PHP/php_mysql_connect.asp
and
http://www.novaksblog.com/2007/10/02/database-connection-with-php/
Object oriented approaches:
PDO:
- http://php.net/manual/en/book.pdo.php
- PDO tutorial: http://www.phpro.org/tutorials/Introduction-to-PHP-PDO.html#1
ADOdb:
- http://adodb.sourceforge.net/
精彩评论