Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/70.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 使用mysql和bootstrap向中插入值?_Php_Mysql_Twitter Bootstrap - Fatal编程技术网

Php 使用mysql和bootstrap向中插入值?

Php 使用mysql和bootstrap向中插入值?,php,mysql,twitter-bootstrap,Php,Mysql,Twitter Bootstrap,这是我需要放入数据库的引导程序 我对bootstrap和mysql很陌生,所以我不知道我是否做得对 还是错了?我急需帮助。顺便说一句,我正在做一个简单的在线预订系统 下面是我正在调整的mysql查询。我使用PDO。我该怎么办?我编辑了这篇文章,这是我以前的一篇小博文项目中完整的db.php <?php namespace ars\DB; // Global annoucement of location within the this page $config = array(

这是我需要放入数据库的引导程序 我对bootstrap和mysql很陌生,所以我不知道我是否做得对 还是错了?我急需帮助。顺便说一句,我正在做一个简单的在线预订系统

下面是我正在调整的mysql查询。我使用PDO。我该怎么办?我编辑了这篇文章,这是我以前的一篇小博文项目中完整的db.php

<?php namespace ars\DB; // Global annoucement of location within the this page


$config = array(
    'username' =>'root',
    'password' => 'kel',
    'database' => 'ars'

);  // function can be reusable
    //function will be put to class namespace (real world)
function connect($config)
{   
    try {
        $conn = new \PDO('mysql:host=localhost;dbname=' . 
                        $config['database'], 
                        $config['username'],
                        $config['password']);



        $conn->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);

        return $conn;
    } catch(exception $e ) {
        return false;
    }
}

    //helper function
function query($query, $bindings, $conn)
{
    $stmt = $conn->prepare($query);
    $stmt->execute($bindings);

    return ( $stmt -> rowCount() > 0 ) ? $stmt : false;

}

   function get($tableName, $conn)
{   try{
        $result = $conn->query("SELECT * FROM $tableName ORDER BY id ");

            return( $result -> rowCount() > 0 )
            ? $result
            : false;
    }catch(Execption $e){
     return false;
    }
}
    // passing the id
function get_by_id($id, $conn)
{   
    // querying the id
    $query =  query(
        'SELECT * FROM posts WHERE id = :id LIMIT 1', 
        array('id' => $id), 
        $conn
    );

    if ($query) return  $query->fetchAll();
    // else

}

这段代码中有许多错误。我不能帮你解决你的问题,但我可以指出其中的一些错误。首先

无需按插入方式订购 您的函数是get,但您正在插入。我可以假设您应该使用select吗?如果是,请了解更多信息。谷歌搜索会帮你省钱

您可以通过显示connect语句来帮助我们。喜欢 mysqli\u connect函数注意:不要按原样使用mysql\u connect 贬值了

要指出的一点是您的 没有名称属性。在选择标记中添加名称=某些选择


如果INSERT语句没有第条下的订单,您没有提供足够的信息供任何人帮助。您在哪里以及如何读取POST变量?你打电话到哪里去?哦,对不起,伙计。我是这个网站的新手,我只是调整了我以前的小博客项目。
<?php namespace ars\DB; // Global annoucement of location within the this page


$config = array(
    'username' =>'root',
    'password' => 'kel',
    'database' => 'ars'

);  // function can be reusable
    //function will be put to class namespace (real world)
function connect($config)
{   
    try {
        $conn = new \PDO('mysql:host=localhost;dbname=' . 
                        $config['database'], 
                        $config['username'],
                        $config['password']);



        $conn->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);

        return $conn;
    } catch(exception $e ) {
        return false;
    }
}

    //helper function
function query($query, $bindings, $conn)
{
    $stmt = $conn->prepare($query);
    $stmt->execute($bindings);

    return ( $stmt -> rowCount() > 0 ) ? $stmt : false;

}

   function get($tableName, $conn)
{   try{
        $result = $conn->query("SELECT * FROM $tableName ORDER BY id ");

            return( $result -> rowCount() > 0 )
            ? $result
            : false;
    }catch(Execption $e){
     return false;
    }
}
    // passing the id
function get_by_id($id, $conn)
{   
    // querying the id
    $query =  query(
        'SELECT * FROM posts WHERE id = :id LIMIT 1', 
        array('id' => $id), 
        $conn
    );

    if ($query) return  $query->fetchAll();
    // else

}