PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
i am making a web site, and for connection i am using mysqli, but on the server this extension is not installed, so i guess i need to change the connection to mysql, but i am doing something wrong, please help
this is the code:
<?php
//login to mysql
function &connectToDb($host, $dbUser, $dbPass, $dbName)
{
// Make connection to MySQL server
if (!$dbConn = @mysql_connect($host, $dbUser, $dbPass)) {
return false;
}
// Select the database
if (!@mysql_select_db($dbName)) {
return false;
}
return $dbConn;
}
$host = 'localhost'; // Hostname of MySQL server
$dbUser = 'name of user'; // Username for MySQL
$dbPass = 'users password'; // Password for user
$dbName = 'database name'; // Database name
$dbConn = &connectToDb($host, $dbUser, $dbPass, $dbName);
?>
then i use tag on $dbconn to the rest of stuff. always worked for me. I keep it in a seperate file outside of my public folder for safe keeping though
it is not working for me,it says
Warning: Missing argument 1 for db_connect(), called in C:\xa
Warning: Missing argument 2 for db_connect(), called in C:\xa
Warning: Missing argument 3 for db_connect(), called in C:\xa
Warning: Missing argument 4 for db_connect(), called in C:\xa
and finally:
Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 261904 bytes) in C:\xampp\h
@barde: If you are using the function suggested by Da_Elf you need to add the variables required by the function i.e db_connect($host, $dbUser, $dbPass, $dbName)
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
ok guys, i think i am going somewhere, i declared the variables, but now this error is coming up:
Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 261904 bytes) in C:\xampp\htd...
a am still a noob , so i am really appreciating your help!
barde, there are two good habits you should acquire to make your life at these forums better. First is to use syntax highlighting for code you post (there's a handy 'PHP Code' button in post editor). Second is naming your threads descriptively - 'hello' just wouldn't do. Both would make it easier for others to help you - and, as such, get you better answers.
Weirdan wrote:barde, there are two good habits you should acquire to make your life at these forums better. First is to use syntax highlighting for code you post (there's a handy 'PHP Code' button in post editor). Second is naming your threads descriptively - 'hello' just wouldn't do. Both would make it easier for others to help you - and, as such, get you better answers.
i was in a hurry and i did not paid attention, i will be careful next time. Thanks
Since you are just beginning to learn PHP/MySQL, I think you will learn much faster by reading a few online tutorials, such as http://www.php-mysql-tutorial.com/wikis ... abase.aspx and dozens of others you can find by entering search terms php mysql tutorial in the search engine of your choice.
i finally got it working. After all, the problem was not in the connection, it was in my other file,
function for getting the categories that was not compatible with changed mysqli to mysql code.