Jump to content

Why cant i connect to database?


forumnz

Recommended Posts

Heres the code...

And yes i didnt write this script but i cant figure it out..

[code]<?php


// database functions :: MySQL

function db_connect($host,$user,$pass) //create connection
{
$r = mysql_connect($host,$user,$pass);
if(preg_match('/^5\./',mysql_get_server_info($r)))db_query('SET SESSION sql_mode=0');
return $r;
}

function db_select_db($name) //select database
{
return mysql_select_db($name);
}

function db_query($s) //database query
{
return mysql_query($s);
}

function db_fetch_row($q) //row fetching
{
return mysql_fetch_row($q);
}

function db_insert_id()
{
return mysql_insert_id();
}

function db_error() //database error message
{
return mysql_error();
}

?>[/code]
Link to comment
https://forums.phpfreaks.com/topic/34469-why-cant-i-connect-to-database/
Share on other sites

This is what I use:

$con = mysql_connect('localaddress', 'account@server', 'password')
 or die('Could not connect: ' . mysql_error());

mysql_select_db('test', $con) or die('Could not select database');

Try making it like that, but of course replace what is in single quotes to fit your computer.

Hope it helps :),
diode
That code is defining functions, not calling them. And since those functions are already reserved by php i don't think that can be done anyway.

Do this:

[code]$conn = mysql_connect("localhost", "user", "password") or die(mysql_error());
mysql_select_db('db_name', $conn) or die(mysql_error());[/code]

but of course replace the information with your own.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.