vendredi 8 juillet 2016
How to connect php to mysql database?
I'm making a search engine for a website and I've never used PHP before and I have been trying to connect my webpage to a mysql database using this code:
$dbhost = 'hosthere';
$dbuser = 'usernamehere';
$dbpass = 'passwordhere';
$conn = mysql_connect($dbhost, $dbuser, $dbpass);
if(! $conn )
{
die('Could not connect: ' . mysql_error());
}
echo 'Connected successfully';
but I also read not to use the mysql_* functions as they will soon not be usable any longer but I haven't seen that anywhere else.
My old code to connect is:
define('DB_SERVER', 'serverhere');
define('DB_SERVER_USERNAME', 'usernamehere');
define('DB_SERVER_PASSWORD', 'passwordhere');
define('DB_DATABASE', 'databasehere');
define('STORE_DB_TRANSACTIONS', 0);
define('DEBUG', 0);
db_connect() or die('Unable to connect to database server!');
Should I just stick with that or use the code at the top?
Inscription à :
Publier les commentaires (Atom)
Aucun commentaire:
Enregistrer un commentaire