PHP+MySQL Database Problem
Ill try to give a short account of what i need help with.
Im currently in the process of building my own forums from scratch using PHP+MySQL. I have the signup.php page and the create_cat.php page. I also have the connect.php which is used to connect to the MySQL database when every page loads. But for some reason it will not let me select which database I want to use. Every page loads fine untill i tell it to include the connect.php. Code:
<?php i also created a test page to see if it could connect to just the main MySQL database using this syntax: Code:
<?php Im also including a copy of the signup.php page just incase the mysql part of that form could have errors i am not seeing. Code:
<?php anyone have an easy solution to this? (besides getting a pre-made forum) Im using Apache 2.2 as well. |
Re: PHP+MySQL Database Problem
The database shouldn't be chosen in mysql_connect. The correct syntax would be:
Code:
if(!mysql_connect($server, $username, $password)) |
Re: PHP+MySQL Database Problem
had that originally. i shall retry it and see if it works.
Edit: odd. i honestly had that code when i initially started this task, and it didn't work. now it does. thank you very much for the assistance. it would have taken me a long time to revert back to that code string. |
Re: PHP+MySQL Database Problem
Might be off on the mysql_error(); part. If not just delete everything after 'or' on line 1
Code:
<?php Code:
SHOW DATABASES; |
Re: PHP+MySQL Database Problem
dont ever connect to databases as the root mysql user in an application script; not even in development.
create a database user that has grants on the specific databases you need to work with and connect as that user: GRANT ALL ON `website`.* TO 'dbuser'@'localhost' IDENTIFIED BY 'salamander'; you should also consider using the mysqli libraries (mysqli_connect, mysqli_pconnect) instead. same usage, better performance. you likely already have the packages installed. |
Re: PHP+MySQL Database Problem
What aperson is saying is the truth. I usually create an account called dev that can create tables and do everything neccesary to create a DB and an account called web that can just use:
SELECT UPDATE INSERT and if needed DELETE MySQLi is the new standard of doing things although not really needed. My work doesn't use it but it makes things much easier and you don't need to worry about sanatizing all your database input with mysql_real_escape_string(). |
Re: PHP+MySQL Database Problem
Thanks for the input guys.
I am 100% new to this so root is just what was there. I will be creating the new accounts later tonight and shall press forward in this learning process. |
Re: PHP+MySQL Database Problem
this thread = good read. I just started working with MySQL a little bit via Java, so it's interesting to see some of the same issues come up from a different (and more common) perspective. Can't wait to start learning some PHP later this semester.
|
All times are GMT -5. The time now is 08:06 AM. |
Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright FlashFlashRevolution