...

View Full Version : Anyone has an example of mysql query using OOP?



che_anj
08-29-2007, 11:30 AM
Hello,

anyone has an example of mysql query using OOP?

example..



$query="select * from users where user_id='$userid'";
$result=mysql_query($query);
$row=mysql_fetch_array($result);

echo $row[name];



how to convert that into oop approach?

thanks...

Bahamut
08-29-2007, 12:34 PM
$mysqli = new mysqli("localhost", "my_user", "my_password", "world");

if (mysqli_connect_errno())
{
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}

$query = "SELECT * FROM users WHERE user_id='$userid'";

if ($result = $mysqli->query($query))
{
while ($row = $result->fetch_assoc())
{
echo $row['name'] ."<br />";
}
$result->close();
}

$mysqli->close();



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum