Re: php script to create mySQL database programmatically



mistral wrote:
"Jerry Stuckle wrote:
"

mistral wrote:

"Jerry Stuckle wrote:
"


mistral wrote:


Need php script to create mySQL database programmatically; since
hosting configuration may not allow create database from script, script
also need eliminate/rewrite all restrictions in appropriate places in
that hosting.


You can make a script to create a database. But you can't make a script
which will hack the host's security settings.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@xxxxxxxxxxxxx
==================

======================================

Need working code to create database programmatically via PHP.

M.


Not a problem. Here are some links to get you started:

For the SQL you need:

http://dev.mysql.com/doc/refman/5.1/en/create-database.html
http://dev.mysql.com/doc/refman/5.1/en/create-table.html

And optionally:

http://dev.mysql.com/doc/refman/5.1/en/create-index.html


From the PHP end, check out:

http://www.php.net/manual/en/function.mysql-connect.php
http://www.php.net/manual/en/function.mysql-create-db.php
http://www.php.net/manual/en/function.mysql-select-db.php
http://www.php.net/manual/en/function.mysql-query.php
http://www.php.net/manual/en/function.mysql-close.php

And for error processing, you'll want:

http://www.php.net/manual/en/function.mysql-error.php

This should get you started.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@xxxxxxxxxxxxx
==================




Code from php.net does not work..

<?php
$link = mysql_connect('localhost', 'mysql_user', 'mysql_password');
if (!$link) {
die('Could not connect: ' . mysql_error());
}

$sql = 'CREATE DATABASE my_db';
if (mysql_query($sql, $link)) {
echo "Database my_db created successfully\n";
} else {
echo 'Error creating database: ' . mysql_error() . "\n";
}
?>


Warning: mysql_connect() [function.mysql-connect]: Can't connect to
local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2) in
/web/www/domain/users/u/username/createdb.php on line 2
Could not connect: Can't connect to local MySQL server through socket
'/var/run/mysqld/mysqld.sock' (2)

Ugly, very ugly..

m.


Are you running this on the server with MySQL installed? If so, it looks like MySQL isn't running or the admin has it set up different from the defaults.

Either way the only one who can tell you more is your hosting company.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@xxxxxxxxxxxxx
==================
.



Relevant Pages

  • Re: Access denied in remote mysql connection
    ... connect to my local mysql database, ... it is what the remote connection ... If you can connect using mysql on the command line, ... Shared Hosting, Reseller Hosting, Dedicated & Semi-Dedicated servers ...
    (comp.lang.perl.misc)
  • Re: mysql connection failing as CGI
    ... some new hosting which comes with a MySQL database but I'm struggling ... to get it working with any perl scripts; the hosting support are being ... The problem basically is that when the script is run as a CGI script it ... the command line it runs fine. ...
    (comp.lang.perl.misc)
  • mysql connection failing as CGI
    ... some new hosting which comes with a MySQL database but I'm struggling ... to get it working with any perl scripts; the hosting support are being ... The problem basically is that when the script is run as a CGI script it ... the command line it runs fine. ...
    (comp.lang.perl.misc)
  • Re: php script to create mySQL database programmatically
    ... "Jerry Stuckle wrote: ... hosting configuration may not allow create database from script, ... You can make a script to create a database. ... Can't connect to local MySQL server through socket ...
    (comp.lang.php)
  • Re: sanitizing uploaded data with a form
    ... i'm escaping quotes for the database, but i wasn't sure what other ... If the script is to display them, ... especially someone else on the server, if you use a shared server and ... Shared Hosting, Reseller Hosting, Dedicated & Semi-Dedicated servers ...
    (alt.php)