Web Hosting Talk







View Full Version : PHP Vs SQL Server


Badie
09-10-2006, 01:10 PM
hi
i want to read data from SQL database by using PHP script , Is that possible?
can someone show me example ?

Thanks

inimino
09-10-2006, 01:23 PM
http://www.php.net/docs.php

Renard Fin
09-10-2006, 01:29 PM
SQL database ... which SQL type ?

I'll give you a very basic example of fetching one row with a MySQL db.


<?php
$conn = mysql_connect($host, $user, $pass)
if (!$conn)
{
trigger_error('DB Server Offline', E_USER_ERROR);
}
else
{
if (!mysql_select_db($dbname, $conn))
{
trigger_error('DB Offline', E_USER_ERROR);
}
else
{
$query = mysql_query("SELECT * FROM my_user_table WHERE UserID = 1");
if (!$query)
{
trigger_error("MySQL error: " . mysql_error(), E_USER_ERROR);
}
else
{
if (!mysql_num_rows($query)
{
trigger_error('No user found !', E_USER_NOTICE);
}
else
{
$data = mysql_fetch_array($query);
echo $data['UserName'];
}
}
}
}
?>



very simple and basic example ... (gosh, havent done procedural since ages !)

Badie
09-10-2006, 01:43 PM
Thankz .. i just test it its work very fine Renard

Badie
09-10-2006, 01:45 PM
http://www.php.net/docs.php

if you write www.php.net (http://www.php.net) will be fine !

lutan
09-10-2006, 04:22 PM
You can grab some classes to do sql queries. Some of them are very easy to use. Look www.phpclasses.org

Renard Fin
09-11-2006, 08:50 AM
Pear::DB seems fine as well or Pear::MDB2 if you want one that is more evolved.