Jump to content

bigmac90

New Members
  • Posts

    2
  • Joined

  • Last visited

Posts posted by bigmac90

  1. I wonder if anyone can help me. I'm creating an application in PHP and am using a SQL server database on my local computer to develop the application. The only problem is I cannot connect to the database. My code looks like



    <?php
    $serverName = "LIAMJAY-PC\SQLEXPRESS"; //serverName\instanceName

    $connectionInfo = array( "Database"=>"ONEDB");
    $conn = sqlsrv_connect( $serverName, $connectionInfo);

    if( $conn ) {
    echo "Connection established.<br />";
    }else{
    echo "Connection could not be established.<br />";
    die( print_r( sqlsrv_errors(), true));
    }
    ?>

    to connect to the database. However, everytime I run the code I keep getting a 18456 error code. Does anybody know what my problem is and if so, what is the solution???


  2. Hi all

     

    I've got a slight problem adding some XML data to a MySQL database. My code looks like: 

     

    // Load XML file
    $xml = simplexml_load_file('products.xml') or die ("Could not load XML file");
     
    // Database variables
    $host = "localhost";
    $username = "user_name";
    $password = "pass_word";
    $dbname = "database_name";
     
    // Foreach piece of XML data - send to MySQL database and put into the xmlFeed_db database
    foreach ($xml->product as $data) {
     
    // MySQL connect to database
    $con = mysql_connect("$host", "$username", "$password") or die ("Unable to connect to database");
    $select_db = mysql_select_db($dbname) or die ("Unable to select database");
     
    // Put all data into numerous variables 
    $id = $data->id;
    $man = $data->manufacturers;
    $des = $data->description;
    $price = $data->price;
    $sku = $data->sku;
    $category = $data->category;
    $subcategory = $data->subcategory;
     
    // SQL statement
    $query = "INSERT INTO tablename VALUES ('$id','$man','$des','$price','$sku','$category','$subcategory')";
     
    // Execute SQL statement
    mysql_query($query) or die ("Insertion Error: " . mysql_error());
     
    // Close MySQL 
    mysql_close();
     
    When I run this script it only stores 249 rows out of 2000 and then it shows an error stating: 
     
    "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 's)', '117.08','CAB-OCTAL-ASYNC=','Networking','Networking Cables')' at line 1"
     
    Does anyone know why this error message is showing? I've looked at my syntax but I can't see a problem. Maybe a fresh pair of eyes can help.
     
    Thanks
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.