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
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
Link to comment
Share on other sites

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.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.