juice Posted April 22, 2014 Share Posted April 22, 2014 im creating a simple website and database for a project with minimal functionality. All i'm supposed to do is create a website that communicates with a database. i chose to do that project with php, ajax and mysql in xamp. Now i've decided to work on the database first, i want it to be portable where i can just put the completed code in folder on a flash drive and go to school with it. where i'll jus be able to copy it to the htdocs folder in the xamp and it will automatically create the database and run all the queries. For some reason, no matter what i try it won't show up in the phpmyadmin databases section. I desperately need help, i wanna kno if my idea is possible and how can i go about it.. here's my code.. thanks much to any help, will be greatly appreciated.. the config.php <?php$db_name="dscdb";$db_user="root";$db_password="";$db_server="localhost";?> heres my connection mysqlconnection.php <?phpinclude($_SERVER['DOCUMENT_ROOT'].'/FinalProject/config.php');$con=mysql_connect($db_server,$db_user,$db_password) or die("Connection Failure: ".mysql_error());mysql_select_db($db_name,$con); ?> and heres my database and query creation.. setup.php <?phpinclude($_SERVER['DOCUMENT_ROOT'].'/Finalproj/config.php');{$con = mysql_connect($db_server,$db_user,$db_password); // database connect//Database creation mysql_query("CREATE DATABASE IF NOT EXISTS $db_name" $con) or die("creating database fails".mysql_error()); USE $db_name; mysql_select_db($db_name) or die(mysql_error()); //Students Table creation mysql_query("CREATE Table IF NOT EXISTS 'Students'('StudID' varchar NOT NULL (15) , primary key (StudentID), 'FirstName' varchar(15) NOT NULL, 'LastName' varchar (15) NOT NULL, 'BirthDate' DATE NOT NULL, 'Address' varchar(30) NOT NULL, 'MajorTitle' Foreign key (MajorTitle) References Majors(MajorTitle) NOT NULL, 'Username' varchar(15) NOT NULL, 'Password' varchar(8) NOT NULL)") or die("Failed to create Table".mysql_error()); mysql_query($con,"INSERT into Students(StudID, FirstName, LastName, BirthDate, Address, MajorTitle, Username, Password) values ('123', 'lee', 'daniel', '1990-01-08', 'Bioche', 'Computer Science', 'lee', 'daniel')"); mysql_query($con,"INSERT into Students(StudID, FirstName, LastName, BirthDate, Address, MajorTitle, Username, Password) values ('456', 'danphil', 'daniel', '1992-06-25', 'Bioche', 'Electronics', 'danphil', 'daniel')"); mysql_query($con,"INSERT into Students(StudID, FirstName, LastName, BirthDate, Address, MajorTitle, Username, Password) values ('789', 'eber', 'raver', '1988-03-28', 'Colihaut', 'Physics', 'eber', 'raver')") //$hashedpassword=sha1("password");// Instructor Table creation mysql_query("CREATE Table IF NOT EXISTS 'Instructors'('InstrucID' varchar NOT NULL (15), primary key (InstrucID), 'FirstName' varchar (15) NOT NULL, 'LastName' varchar (15) NOT NULL, 'Address' varchar(30) NOT NULL, 'Username' varchar (15) NOT NULL, 'Password' varchar(8) NOT NULL) ") or die("Failed to create Table".mysql_error()); mysql_query($con,"INSERT into Instructors(InstrucID, FirstName, LastName, Address, Username, Password) values ('abc', 'larry', 'thomas', '1982-09-14', 'Goodwill', 'larry', 'thomas')"); mysql_query($con,"INSERT into Instructors(InstrucID, FirstName, LastName, Address, Username, Password) values ('def', 'james', 'victor', '1986-09-06', 'Grandbay', 'james', 'victor')"); mysql_query($con,"INSERT into Instructors(InstrucID, FirstName, LastName, Address, Username, Password) values ('ghi', 'barnaby', 'jack', '1977-11-23', 'ireland', 'barnaby', 'jack')");//Registrar Table creation mysql_query("CREATE Table IF NOT EXISTS 'Registrars' ('RegID' varchar NOT NULL (15), primary key(RegID), LastName varchar (15) NOT NULL, Username varchar (15) NOT NULL, Password varchar(15) NOT NULL) ") or die("Failed to create Table".mysql_error()); mysql_query($con,"INSERT into Registrars(RegID, LastName, Username, Password) values ('abc123', 'jones', 'jones', 'jones')"); //Majors table creation mysql_query("CREATE Table IF NOT EXISTS 'Majors' ('MajorType' varchar NOT NULL (15), primary key (MajorID), 'MajorTitle' varchar (20) NOT NULL)") or die("Failed to create Table".mysql_error()); mysql_query($con,"INSERT into Majors('MajorType', 'MajorTitle') values ('FAS', 'Computer Science')"); mysql_query($con,"INSERT into Majors('MajorType', 'MajorTitle') values ('FAS', 'Physics')"); mysql_query($con,"INSERT into Majors('MajorType', 'MajorTitle') values ('FAAT', 'Electronics')"); echo "<script>alert('The webApp has been installed successfully')</script> "; mysql_close();}}?> Link to comment Share on other sites More sharing options...
davej Posted April 22, 2014 Share Posted April 22, 2014 Stop. Go back and start over with mysqli or PDO. Link to comment Share on other sites More sharing options...
juice Posted April 22, 2014 Author Share Posted April 22, 2014 so that means i should keep nothing? Link to comment Share on other sites More sharing options...
juice Posted April 22, 2014 Author Share Posted April 22, 2014 thanks alot though davej, doing some reseach on pdo now.. Every things seems to make alot of sense for now, if i encounter any problems i will let the forum know.. Link to comment Share on other sites More sharing options...
davej Posted April 22, 2014 Share Posted April 22, 2014 Just re-write what you have using mysqli or PDO. Link to comment Share on other sites More sharing options...
juice Posted April 22, 2014 Author Share Posted April 22, 2014 i tried mysqli.. but still nothing. im still tryna figure erything out with the PDO Link to comment Share on other sites More sharing options...
juice Posted April 23, 2014 Author Share Posted April 23, 2014 i'm starting to think now its a problem the phpmyadmin... i've tried 3 different ways now.. mysql, mysqli and now PDO.. can any one suggest something i could try or tweak.. here's the PDO code i hav now <?php$db_name="dscdb";$db_user="root";$db_password="";$db_server="localhost";$user='admin';$password=""; $dbconn = new PDO(mysql:host = $db_server; $db_name; charset = utf8, $db_user, $db_password); // create a new database $dbconn->exec("CREATE DATABASE '$db_name`; CREATE USER '$user'@'localhost' IDENTIFIED BY '$passw'; GRANT ALL ON `$db_name`.* TO '$user'@'localhost'; FLUSH PRIVILEGES;") or die(print_r($dbconn->errorInfo(), true)); // check to see if database was successfully created if($db_name){ echo 'connected to database'; } else { echo 'Not Successfuly Created'; } $dbconn = null; ?> Link to comment Share on other sites More sharing options...
davej Posted April 23, 2014 Share Posted April 23, 2014 Maybe... $dbconn = new PDO("mysql:host=$db_server; dbname=$db_name;" charset=utf8, $db_user, $db_password); ...based on... http://wiki.hashphp.org/PDO_Tutorial_for_MySQL_Developers Link to comment Share on other sites More sharing options...
juice Posted April 23, 2014 Author Share Posted April 23, 2014 as i said it has to be some configuration problem with the phpmyadmin.. nothing is not working Link to comment Share on other sites More sharing options...
Don E Posted April 23, 2014 Share Posted April 23, 2014 What are you using to develop; WAMP, XXAMP, MAMP, LAMP? Or on a live server? Maybe you need to update your PHP to a version that supports mysqli, PDO. If you're using a version that has mysqli/PDO support, then something wrong with configuration somewhere most likely. Link to comment Share on other sites More sharing options...
justsomeguy Posted April 23, 2014 Share Posted April 23, 2014 You're not using phpMyAdmin for this. You're using PHP, PDO, and MySQL. Link to comment Share on other sites More sharing options...
juice Posted April 23, 2014 Author Share Posted April 23, 2014 (edited) yh.. im using xamp.. i even reinstalled it last night.. installed the latest phpmyadmin to.. every thing is up to date.. so far i tried; mysql, mysqli, PDO and now perl and nothing is working.. im really beigining to think its a configuration problem in the phpmyadmin, mysql server or xampp.. can anyone tell me what should i try.. im using the latest php 5.5.9, phpmyadmin 4.1.13, MySQL 5.6.16 and apache 2.4.7... this is really keeping me back now n giving headaches.. Edited April 23, 2014 by juice Link to comment Share on other sites More sharing options...
juice Posted April 23, 2014 Author Share Posted April 23, 2014 what do you mean justsomeguy, can you explain a bit further please? Link to comment Share on other sites More sharing options...
davej Posted April 23, 2014 Share Posted April 23, 2014 PhpMyAdmin allows you to administer the database. You're running Php code. That has nothing to do with PhpmyAdmin other than using the database and tables that you probably created using PhpMyAdmin. You might also enter a few test values into the tables using PhpMyAdmin. Your first Php debugging test would probably be to prove that your code can read those tables and obtain those known values. Link to comment Share on other sites More sharing options...
juice Posted April 24, 2014 Author Share Posted April 24, 2014 ok thats a good idea.. thanks Link to comment Share on other sites More sharing options...
juice Posted April 24, 2014 Author Share Posted April 24, 2014 well i added the database to the phpmyadmin, manually and then tried to connect to it wih php.. i used mysqli.. it connected .. now i'm having trouble adding the tables with php code but i'll get around it sooner or later... thanks for everyones help... if i get any other problem i will let you'll know... Link to comment Share on other sites More sharing options...
davej Posted April 24, 2014 Share Posted April 24, 2014 You normally do not want a website to have any more database privileges than it needs for ordinary operation. http://en.wikipedia.org/wiki/Principle_of_least_privilege Link to comment Share on other sites More sharing options...
juice Posted April 24, 2014 Author Share Posted April 24, 2014 over 5 hours now n i still can't create a table.. any suggestions? im gonna try using PDO tomo, if i don't get any luck.. Link to comment Share on other sites More sharing options...
Don E Posted April 24, 2014 Share Posted April 24, 2014 Show us the code you're writing to create tables with PHP. As I'm sure you're aware, you can create tables(for a database) via phpmyadmin as well. Link to comment Share on other sites More sharing options...
birbal Posted April 24, 2014 Share Posted April 24, 2014 (edited) please Dont be confused. you can go either way with pdo or mysqli. if code with one of them is not working dont switch it to another. it wont help anything. as you are starting stick with any one of them. as already told, phpmyadmin is nothing but a php application which interacts with mysql server. so if you can work with phpmyadmin, it is obvious that you have mysql,apache and php is up and running. after that if something in your code is not working dont assume and try to debug things. $dbconn = new PDO(mysql:host = $db_server; $db_name; charset = utf8, $db_user, $db_password); $dbconn->setAttribute(PDO::ATTR_ERRORMODE,PDO::ERRORMODE_EXCEPTION); //It will throw exception when an error occurs. it will also show the reason of error with error message unless it is for educational purpose table creation (or any other DDL part) usually does not happen in php scripts. you set up the table in phpmyadmin. and mostly use Database Query Language(DQL) or DML from your php script. Edited April 25, 2014 by birbal 1 Link to comment Share on other sites More sharing options...
justsomeguy Posted April 24, 2014 Share Posted April 24, 2014 unless it is for educational purpose table creation (or any other DML part) usually does not happen in php scripts. you set up the table in phpmyadmin.That's right, I never write code to create tables in my actual PHP scripts. I use phpMyAdmin to create the database and all of the tables first, and then my PHP code just uses the existing database to add records, delete them, update them, read them, etc. 1 Link to comment Share on other sites More sharing options...
juice Posted April 27, 2014 Author Share Posted April 27, 2014 thanks for all the advice but as i said in the beginning its for a school project and i want the code to be portable.. so i can transfer it to my schools' computer and it will automaticall create the database tables, which will make my website fully functional... i found the problem in my code after trial n error.. it was the quotation marks i placed in my SQl queries... i'm tryna finish it right now with msqli cause there's alot more documentation and examples online for it than PDO.. but when i'm done i will try doing it in PDO as well, it seems easier and faster to code because or its object oriented nature... Link to comment Share on other sites More sharing options...
birbal Posted April 29, 2014 Share Posted April 29, 2014 i want the code to be portable You can export and import database and tables. phpmyadmin has option for doing so. Link to comment Share on other sites More sharing options...
davej Posted April 29, 2014 Share Posted April 29, 2014 You can also write a script to create the tables. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now