Jump to content
Fórum Script Brasil
  • 0

Call to a member function prepare() on null



Olá pessoal, meu sistema de postagens está dando o erro Call to a member function prepare() on null na linha 54. Alguém sabe como resolver? 

Segue abaixo o código.

      include_once '_php/BD.class.php';
      global $conn;
        ini_set('display_errors', true);
        <form name="entrar" method="post" action="#">
                <textarea type="text"name="texto" cols="22" rows="6" id="textoPostagem"></textarea>
            <input type="submit" name="postar" value="Postar">

    <form method="post" action="_php/recebe_upload.php" enctype="multipart/form-data">
  <input type="file" name="arquivo" />
  <input type="submit" value="Enviar" />


       if(isset($_POST['postar']) && empty($_POST['textoPostagem'])){
        $post = $_POST['texto'];
        $data = date("Y/m/d");
        if (strlen($_POST['texto'])) {
            //$sql = "INSERT INTO mydb (postagens) VALUES('$post')";
            $sql = $conn->prepare("insert into mydb (postagens) values ('$post')");
            $sql->bind_param(1, $post);
            $sql->execute() or exit(print_r($sql->errorInfo(), true));; 
            $stmt2 = $conn->prepare("select postagens from postagens");

            while ($stmt2->fetch(PDO::FETCH_OBJ)) {

                /* ($exibir = mysqli_fetch_array($executar))
                  echo $exibir['texto'];
                  echo " "; */
                echo $nome;
                echo $reg->texto;
                echo $date;
        } else {
            echo "Digite um texto";




Código da conexão com BD

	class BD{
		private static $conn;
		static function getConn(){
			if (is_null (self::$conn)) {
				self::$conn = new PDO('mysql:host=localhost;dbname=mydb','root','');
			return self::$conn;


Agradeço desde já a ajuda. 

Link to comment
Share on other sites

1 answer to this question

Recommended Posts

Join the conversation

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

Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  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.


  • Forum Statistics

    • Total Topics
    • Total Posts
  • Create New...