Results 1 to 4 of 4

Thread: PHP scripts using CL

  1. #1
    Junior Registered
    Join Date
    Aug 2007
    Posts
    2

    PHP scripts using CL

    Hi All,

    I have this scenario, hopefully it can be possible to implement it in php scripting using command line.

    I have a datatbase (MySQL) to connect.

    By using command prompt:
    - So i would like to have a php script to connect to my mysql, and it says it's connected successfully...(i have this code done) additionally, I want this script to allow the end user to enter his/her own database name...be able to create a name which will automatically be generated into mysql. Another script to drop the database ?????? and also give options to user....do you really want to delete or drop ...????
    Can both php (connect & create name) be in the same script? how?

    Once that's done, the user must be able also to connect through command prompt to a URL, in order to retrieve data and store them into mysql.

    Can I find some sample working codes to illustrate all?

    Hope to get your comments soooooonnnnn...
    thanks a lot for reading....

  2. #2
    Administrator Chris's Avatar
    Join Date
    Feb 2003
    Location
    East Lansing, MI USA
    Posts
    7,055
    PHP can natively interface with MySQL databases.

    http://us3.php.net/manual/en/ref.mysql.php

    If you feel you really must work with the shell you may need to set special permissions with your php scripts to allow them to run as a superuser (risky) or you'll need to use suexec or something in the script.

    http://us3.php.net/manual/en/function.exec.php

    But really, it can all be done with those native PHP functions.
    Chris Beasley - My Guide to Building a Successful Website[size=1]
    Content Sites: ABCDFGHIJKLMNOP|Forums: ABCD EF|Ecommerce: Swords Knives

  3. #3
    Junior Registered
    Join Date
    Aug 2007
    Posts
    2
    thanks for the reply....

    I am running this current script but it can only create the first table in the database...I don't know why.
    Am I missing something here?

    PHP code
    Code:
    <?php
    $link = mysql_connect('localhost', 'username', 'password');
    if (!$link) {
    die('Could not connect: ' . mysql_error());
    }
    
    $sql = 'CREATE DATABASE test2';
    if (mysql_query($sql, $link)) {
    echo "Database test2 created successfully\n";
    } else {
    echo 'Error creating database: ' . mysql_error() . "\n";
    }
    // Create tables in test2 database
    
    mysql_select_db("test2", $link);
    
    $sql = "CREATE TABLE car (
    title varchar(255) NOT NULL,
    description varchar(255) NOT NULL,
    priority tinyint(2) NOT NULL default '0'
    ) TYPE=InnoDB\n";
    
    mysql_query($sql, $link);
    if (mysql_error()) echo __line__.") Error creating table: ".mysql_error();
    
    //Create links table
    $sql = "CREATE TABLE links (
    type varchar(20) NOT NULL default '',
    resource varchar(255) NOT NULL,
    ) TYPE=InnoDB\n";
    
    mysql_query($sql, $link);
    if (mysql_error()) echo __line__.") Error creating table: ".mysql_error();
    
    //Create home table
    $sql = "CREATE TABLE home (
    name varchar(255) NOT NULL,
    title varchar(255) NOT NULL default '',
    description varchar(255) NOT NULL default '',
    ) TYPE=InnoDB\n";
    
    mysql_query($sql, $link);
    if (mysql_error()) echo __line__.") Error creating table: ".mysql_error();
    
    //Create people table
    $sql = "CREATE TABLE people (
    name varchar(20) NOT NULL default '',
    address varchar(255) NOT NULL
    resource varchar(255) NOT NULL,
    
    ) TYPE=InnoDB\n";
    
    echo "car,home,links, & people tables in the relational database (".test2.") have been successfully created!\n";
    mysql_query($sql, $link);
    if (mysql_error()) echo __line__.") Error creating table: ".mysql_error();
    mysql_close($link);//Close connection
    ?>

  4. #4
    Registered
    Join Date
    Aug 2006
    Location
    Sacramento, CA
    Posts
    208
    The problem is for all the rest of the tables after the first, you have a comma (,) after the last field, before the closing ")".

    Code:
    //Create links table
    $sql = "CREATE TABLE links (
    type varchar(20) NOT NULL default '',
    resource varchar(255) NOT NULL,
    ) TYPE=InnoDB\n";
    You have to remove that last extra comma (the red one) from each of them and it should work.
    ________
    328
    Last edited by rpanella; 03-17-2011 at 10:58 AM.

Similar Threads

  1. Review: Professional PHP Programming
    By Chris in forum Books
    Replies: 6
    Last Post: 07-17-2013, 05:26 AM
  2. Using PHP to produce PHP really screws with the head.
    By KLB in forum Website Programming & Databases
    Replies: 8
    Last Post: 02-14-2007, 11:36 AM
  3. Replies: 0
    Last Post: 07-31-2006, 09:57 AM
  4. New Scripts
    By bestpost in forum The Marketplace
    Replies: 1
    Last Post: 07-23-2006, 09:34 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •