Jump to content

Failing to open an sqlite database.


Recommended Posts

This is bothering me beyond belief I'm hoping that someone here might be able to help me. I've tried playing around with a few permissions, that could be the problem. Basically if I try to create/open a database it will create an error I've narrowed it down to this one line and it's the first one which leads me to believe that it's either a php configuration problem or a permissions thing. Running IIS 7.0

 

<html>
<body>
<?php
$dbh = new PDO('sqlite:poems.sqlite');
?>

<?php
//phpinfo();
$name=$_POST["userName"];
$contact=$_POST["userContact"];
$poem=str_replace("
","<br />",$_POST["userPoem"]);
$comment=str_replace("
","<br />",$_POST["userComment"]);




$query='INSERT INTO '.$dbh.' (name,contact,body,desc) VALUES ('.$name.','.$contact.','.$poem.','.$comment.')';
echo $query;
/*$db->exec('INSERT INTO '.$db.' (name,contact,body,desc) VALUES ('.$name.','.$contact.','.$poem.','.$comment.')');*/
?>

<p>
<b>Your name:</b> <?php echo $name; ?><br />
<b>Your contact info:</b> <?php echo $contact; ?><br />
<b>Your Poem:</b><br /> <?php echo $poem; ?><br />
<b>Your Comments:</b><br /> <?php echo $comment; ?>
</p>
</body>
</html> 

<?php $dbh = null; ?> 

 

Any and all help is appreciated. Would Apache be any better? I'm considering just switching over if so.

Link to comment
Share on other sites

I think you should reread what thorpe posted and then read your query statement -

Ah, yeah, that'll be your problem. Your using $dbh, (which is a connection object) as the table name in your query (which should be a string).

 

The $dbh variable is NOT your table name, it is your database connection object. It does not belong in the query. Your table name belongs in the query.

Link to comment
Share on other sites

Right, I read it but since I'm not used to object/class programming I assumed that the database connection object could be represented as an integer which I could echo to see if my open function succeeded or not. That aside, I've cleaned up my query and I'm getting this error:

 

Warning: PDO::exec(): SQLSTATE[HY000]: General error: 1 near "Morrison": syntax error in C:\inetpub\wwwroot\form.php on line 26 Array ( [0] => HY000 [1] => 1 [2] => near "Morrison": syntax error )

 

Where Morrison is the name. I've used sqlite before, awhile ago mind, and I can't see the syntax error regarding the query. Could it be a PHP error I've made?

 

Got that one sorted out, forgot about the ' ' since they were already there for adding the strings together. New problem is:

 

Warning: PDO::exec(): SQLSTATE[HY000]: General error: 8 attempt to write a readonly database in C:\inetpub\wwwroot\form.php on line 26 Array ( [0] => HY000 [1] => 8 [2] => attempt to write a readonly database ) 

 

But I think I can handle it on my own, thanks for all your help.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.