PHP Newsletter

Join now and receive weekly updates pertianing to the world of PHP.

Polls

What do you think about the new PHPMine Design?
Awesome
Not Bad
Sucks

PHP Gigs By City

PHP Jobs By Topic

Advertisements

Hey, you can pull and put stuff in your database using php, right..?

Asked 2010-03-09 20:22:35 by SoBeIt

Right? It is possible to edit files using php and so should be to use it as sole language accessing database. So why do we need mysql or whatever it is. Sql/Mysql. ??:)

What is that mysql can do that Php can't?
Here people are reaching to two opinions
1st you cant change/create database using only php
2nd Heck, yeah its possible.

Anwered 2010-03-10 09:02:40 by TheMadProfessor

'Files' yes - only php is needed. (that's why such are often referred to as 'flat files')

'Databases' no - those require SQL (Structured Query Language) code to interact with and that needs a DBMS (database management system) to interpret the SQL.

Anwered 2010-03-09 20:32:15 by Silent

MySQL is a relational database. PHP is a programming language and runtime environment that can be used, among other things, to access databases.

Your question is kind of like asking: "I can use a gas pump to put gas in my car, so why do I need a gas tank?"

Anwered 2010-03-09 20:30:41 by Em-Em

PHP uses SQL to access and change your data. PHP can't change the data without SQL.

Anwered 2010-03-09 20:25:26 by no

mySQL is the database.

PHP grabs stuff from the database, which is usually a mySQL database.

Anwered 2010-03-09 20:51:06 by Rami

mySQL is a database language and as you said, PHP is a programming language that extracts this information to display it on a web page. HOWEVER, it is possible with PHP to change the SQL code directly on your PHP page and without accessing your database.

First off, you can create a database directly from PHP with the mysql_create_db function and if you decide to work with PHP myAdmin interface for database which is very easy, you can connect to it using the mysql_connect function. Here's a simple script I made to connect to a database:

$server = 'localhost';
$user = 'root';
$password = '';

$DB = 'databaseNameHere';
$db_link = mysql_connect($server, $user, $password) or die('Connexion Error or another custom message to say the database connexion failed'. mysql_error());
mysql_select_db($DB) or die('You chose the wrong database name' . mysql_error());

After that what you can do is display the information the msql_query() function. If you know SQL language you can store them in PHP variables, for example :
$command = 'SELECT * FROM yourTableName';
$query = mysql_query($command);
if(!$query)
{
die(Invalid Request : ' . mysql_error());

}else{
echo $query;
}

That's pretty much the basics, if you're still interested Google's your friend !

Questions and answers provided by the Yahoo Answers Community.