Outline ·
[ Standard ] ·
Linear+
php connect mysql~
|
TSlucashii
|
Jan 28 2006, 08:53 AM, updated 20y ago
|
Getting Started

|
I am new toward php and i have just install wamp trying out the online tutorial~I came across this script which i just cant get it to work...with this script it shud add the tables and fields which could be access in myphpadmin right?Thanks to pros here in advance~
<? $user="username"; $password="password"; $database="database"; mysql_connect(localhost,$user,$password); @mysql_select_db($database) or die( "Unable to select database"); $query="CREATE TABLE contacts (id int(6) NOT NULL auto_increment,first varchar(15) NOT NULL,last varchar(15) NOT NULL,phone varchar(20) NOT NULL,mobile varchar(20) NOT NULL,fax varchar(20) NOT NULL,email varchar(30) NOT NULL,web varchar(30) NOT NULL,PRIMARY KEY (id),UNIQUE id (id),KEY id_2 (id))"; mysql_query($query); mysql_close(); ?>
|
|
|
|
|
|
alvinz_c
|
Jan 28 2006, 09:55 AM
|
|
QUOTE(lucashii @ Jan 28 2006, 08:53 AM) I am new toward php and i have just install wamp trying out the online tutorial~I came across this script which i just cant get it to work...with this script it shud add the tables and fields which could be access in myphpadmin right?Thanks to pros here in advance~ <? $user="username"; $password="password"; $database="database"; mysql_connect(localhost,$user,$password); @mysql_select_db($database) or die( "Unable to select database"); $query="CREATE TABLE contacts (id int(6) NOT NULL auto_increment,first varchar(15) NOT NULL,last varchar(15) NOT NULL,phone varchar(20) NOT NULL,mobile varchar(20) NOT NULL,fax varchar(20) NOT NULL,email varchar(30) NOT NULL,web varchar(30) NOT NULL,PRIMARY KEY (id),UNIQUE id (id),KEY id_2 (id))"; mysql_query($query); mysql_close(); ?> Hi, try change this mysql_connect( "localhost",$user,$password); you can use mysql_error() for detail of error. Hope this helps...
|
|
|
|
|
|
se7en
|
Jan 28 2006, 12:45 PM
|
resistance is futile
|
it should be mysql_connect('localhost',$user,$password);
you can add in the following lines below that to see if it connected or what is the error (database permission etc etc)
if (!$link) { die('Could not connect: ' . mysql_error()); } echo 'Connected successfully';
|
|
|
|
|
|
Seventh7
|
Jan 28 2006, 01:00 PM
|
|
please make sure that u change the $user, $password, $database according to ur username, password and database name u have created.
|
|
|
|
|
|
TSlucashii
|
Jan 29 2006, 12:45 AM
|
Getting Started

|
thanks for the reply but i still cant seem to get the code to work.
I created this php code and save it as create.php...so i run this code on my explorer and this table that contains the field shud be accessible in myphpadmin?or do i need to do it manually in myphpadmin and then access it from php?
how do i change the password?cuz i am still using the default setting of the install mysql~
se7en: the code u gave me...where shud i put it?
i am still new to this php so any advice would be appreciated~Thanks~
|
|
|
|
|
|
Seventh7
|
Jan 29 2006, 01:30 AM
|
|
lets try with simple code first
go to mysql, create a new database and a table
in this example, i put a new database name is mydb and the table name is mytab
so u try put the code in here ur php and see if it can connect or not
<?php $conn = mysql_connect("localhost"); mysql_select_db("mydb") or die("error connecting to dbase");
?>
try that..and come back to us to update...........
|
|
|
|
|
|
TSlucashii
|
Jan 30 2006, 08:32 AM
|
Getting Started

|
haha my bad cuz i am really a beginner and i havent really read through the whole myphpadmin configuration,its working ok now~thanks all the pros~
|
|
|
|
|