forumnz Posted January 16, 2007 Share Posted January 16, 2007 Heres the code...And yes i didnt write this script but i cant figure it out..[code]<?php// database functions :: MySQLfunction 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 More sharing options...
Psycho Posted January 16, 2007 Share Posted January 16, 2007 Those are just functions for working with the database. You need to have code that calls those functrions. Link to comment https://forums.phpfreaks.com/topic/34469-why-cant-i-connect-to-database/#findComment-162349 Share on other sites More sharing options...
forumnz Posted January 16, 2007 Author Share Posted January 16, 2007 Ok, if I can write that code how would I link it to the page? Would I put it in the page or would I include it? Am i making sense? Link to comment https://forums.phpfreaks.com/topic/34469-why-cant-i-connect-to-database/#findComment-162354 Share on other sites More sharing options...
diode Posted January 16, 2007 Share Posted January 16, 2007 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 https://forums.phpfreaks.com/topic/34469-why-cant-i-connect-to-database/#findComment-162355 Share on other sites More sharing options...
Tandem Posted January 16, 2007 Share Posted January 16, 2007 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 https://forums.phpfreaks.com/topic/34469-why-cant-i-connect-to-database/#findComment-162356 Share on other sites More sharing options...
dgiberson Posted January 16, 2007 Share Posted January 16, 2007 you need to set $host, $user and $pass in order to connect.This manner will allow you to use an almost persistent connection as opposed to writing out the connection statement on every page. Link to comment https://forums.phpfreaks.com/topic/34469-why-cant-i-connect-to-database/#findComment-162359 Share on other sites More sharing options...
forumnz Posted January 16, 2007 Author Share Posted January 16, 2007 Ok thanks but how do I make the password link to $pass and the db name link to $name? etc. Link to comment https://forums.phpfreaks.com/topic/34469-why-cant-i-connect-to-database/#findComment-162366 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.