Codeigniter doesn't let me execute query
Posted: Mon Jul 06, 2009 8:55 am
I was assigned to setup a new page in a site using the codeigniter framework however because I don't know how to use it and also because the code is badly messed up I wanted to inject my own coding ways.
I am trying to do a simple query in the database (not using the framework way).
first I include my db script to connect,
Then in header.php
I get the warning:
I am trying to do a simple query in the database (not using the framework way).
first I include my db script to connect,
Code: Select all
<?php
/*
DATABASE CONNECT
*/
$db_host = "localhost";
$db_username = "xxx";
$db_password = "xxx";
$db_database = "xxx";
$db_connection = mysql_connect($db_host,$db_username,$db_password);
if (!$db_connection)
{
die("<font color='red'>Error</font>: Could not connect to database: " . mysql_error());
}
mysql_query("SET NAMES 'utf8'");
$db_database=mysql_select_db($db_database, $db_connection);
if (!$db_database)
{
die("<font color='red'>Error</font>: Could not connect to the particular database: " . mysql_error());
}
?>Code: Select all
$vrs_query="SELECT * FROM cars";
$vrs_result=mysql_query($vrs_query);
while ($row = mysql_fetch_row($vrs_result))
{
$get_title=$row['cars_title'];
echo $get_title;
$site_title=$site_title." | ".$get_title;
}Any help with this?A PHP Error was encountered
Severity: Warning
Message: mysql_fetch_row(): supplied argument is not a valid MySQL result resource
Filename: views/header.php